#pragma once
#include "SkinSysHeader.h"
#include <vector>

#define SKIN_DECLARE_CLASS_NAME(classname)   \
public:                                                 \
    \
    virtual LPCTSTR GetClassName()                        \
{                                                   \
    return classname;                               \
    }                                                   \
    \
    virtual LPCTSTR GetObjectClass()                     \
{                                                   \
    return classname;                               \
    }                                                   \
    \
    virtual BOOL IsClass(LPCTSTR lpszName)               \
{                                                   \
    return _tcscmp(GetClassName(), lpszName)  == 0;  \
    }                                                   \
 
#define SKIN_ATTRIBUTE_BEGIN()                                                                         \
public:                                                                                                              \
    virtual HRESULT SetProperty(LPCTSTR strAttribName,LPCTSTR strValue)                    \
{                                                                                                                    \
    HRESULT hRet = __super::SetProperty(strAttribName,strValue);                                            \
    if (SUCCEEDED(hRet))                                                                                             \
        return hRet;                                                                                                 \
 
#define SKIN_ATTRIBUTE_INT(AttribName,varValue)                                       \
    if (0==_tcscmp(AttribName,strAttribName))                                                                        \
    {                                                                                                                \
        varValue=_ttoi(strValue);                                                                                    \
        hRet=S_OK;                                                                                                   \
    }                                                                                                                \
    else                                                                                                             \
 
#define SKIN_ATTRIBUTE_LONG(AttribName,varValue)                                       \
	if (0==_tcscmp(AttribName,strAttribName))                                                                        \
	{                                                                                                                \
		varValue=_ttol(strValue);                                                                                    \
		hRet=S_OK;                                                                                                   \
	}                                                                                                                \
	else

#define SKIN_ATTRIBUTE_SIZE(AttribName,varValue)                                       \
    if (0==_tcscmp(AttribName,strAttribName))                                                                         \
    {                                                                                                                 \
        _stscanf_s(strValue, _T("%i,%i"), &varValue.cx, &varValue.cy);                                                \
        hRet=S_OK;                                                                                                    \
    }                                                                                                                 \
    else                                                                                                              \
 
#define SKIN_ATTRIBUTE_RECT(AttribName,varValue)                                                                            \
    if (0==_tcscmp(AttribName,strAttribName))                                                                               \
    {                                                                                                                       \
        _stscanf_s(strValue, _T("%ld,%ld,%ld,%ld"), &varValue.left, &varValue.top, &varValue.right, &varValue.bottom);      \
        hRet=S_OK;                                                                                                          \
    }                                                                                                                       \
 
#define SKIN_ATTRIBUTE_STRING(AttribName,varValue)                                                        \
    if (0==_tcscmp(AttribName,strAttribName))                                                                           \
    {                                                                                                                   \
        varValue=strValue;                                                                                              \
        hRet=S_OK;                                                                                                      \
    }                                                                                                                   \
    else                                                                                                                \
 
#define SKIN_ATTRIBUTE_BOOL(AttribName,varValue)                                                    \
    if (0==_tcscmp(AttribName,strAttribName))                                                       \
    {                                                                                               \
        if (0==_tcscmp(strValue,_T("false")))                                                        \
        {                                                                                           \
            varValue=FALSE;                                                                          \
        }                                                                                           \
    }                                                                                               \
    else                                                                                            \
 
#define SKIN_ATTRIBUTE_COLOR(AttribName,varValue)                                                   \
    if (0==_tcscmp(AttribName,strAttribName))                                                        \
    {                                                                                                \
        int iLen=_tcslen(strValue)*sizeof(TCHAR);                                                    \
        TCHAR* lpszTemp=new TCHAR[iLen+1];                                                           \
        _tcscpy_s(lpszTemp,iLen+1,strValue);                                                         \
        lpszTemp[iLen]=_T('\0');                                                                     \
                                                                                                     \
        int r=0;                                                                                     \
        int g=0;                                                                                     \
        int b=0;                                                                                     \
        LPCTSTR lpszStr=strValue;                                                                    \
        while (_T('\0')!=*lpszStr)                                                                   \
        {                                                                                            \
            TCHAR* pos=(TCHAR*)_tcschr(lpszStr,_T(','));                                             \
            if (NULL!=pos)                                                                           \
            {                                                                                        \
                lpszTemp[pos-strValue]=_T(' ');                                                      \
                lpszStr+=pos-strValue;                                                               \
            }                                                                                        \
            lpszStr++;                                                                               \
        }                                                                                            \
        _stscanf_s(lpszTemp,_T("%i %i %i"),&r,&g,&b);                                                \
        delete[] lpszTemp;                                                                           \
        lpszTemp=NULL;                                                                               \
        varValue=RGB(r,g,b);                                                                         \
    }                                                                                                \
 

#define SKIN_ATTRIBUTE_END()                                                                           \
        return E_FAIL;                                                                                               \
    return hRet;                                                                                                     \
}                                                                                                                    \
 
class CSkinObject
{
public:
    CSkinObject( void );

    virtual ~CSkinObject( void );

//    void SetParent(CSkinObject* pParent);

//    CSkinObject* GetParent();

    void SetChild( CSkinObject* pChild );

    CSkinObject* GetChild();

//   CSkinObject* FindChild(HSKINHWND hWnd);

    virtual BOOL LoadNode( IXMLDOMNode* pNode );

    virtual HRESULT SetProperty( LPCTSTR lpszAttName, LPCTSTR lpszAttValue );

//   virtual BOOL CreateSkinWindow()=0;

    virtual LPCTSTR GetClassName()PURE;

private:

//    CSkinObject* m_pParent;

//    CSkinObject* m_pChildObj;

    std::vector<CSkinObject*> m_vecChildObj;
};